#include "../include/Monstre.h"
#include <assert.h>
#include <string.h>

Monstre::Monstre(string p_nom, int p_vie, int p_mana,
                   int p_force, int p_endurance,
                   int p_vitesse, int p_mysticisme, int p_point_action,
                   int p_pos_x, int p_pos_y, int p_rarete, int p_experience_donnee) : Creature (p_nom, p_vie, p_mana,
                                                                                                                p_force,
                                                                                                                p_endurance, p_vitesse,
                                                                                                                p_mysticisme,
                                                                                                                p_point_action,
                                                                                                                p_pos_x,
                                                                                                                p_pos_y)
{
    //ctor
    rarete = p_rarete;
    experience_donnee = p_experience_donnee;
    strcpy(ad_image, "data/Monstre/"); //A remplacer par l'adresse de l'image du monstre pour les monstres visible sur la carte
}

Monstre::Monstre(string p_nom) : Creature (p_nom)
{

}


Monstre::~Monstre()
{

}

int Monstre::recup_rarete ()
{
    return rarete;
}

int Monstre::recup_experience_donnee ()
{
    return experience_donnee;
}

void Monstre::monstre_test_non_regression ()
{
    using std::cout;

    int f_vie, f_force, f_endurance, f_vitesse, f_point_action;

    cout << "_______________________________________________________________________\n" ;
    cout << "_______________________________________________________________________\n \n";
    cout << "Monstre : \n";
    cout << "_______________________________________________________________________\n \n";

    assert (this != NULL);
    cout<<"Memoire alloue... \n \n";

    cout<<"Test de recuperation des champs : \n \n";

    cout<<"Nom : "<<nom;
    assert (this->recup_nom () == nom);
    cout<<" ..... OK \n";

    cout<<"Rarete : "<<rarete;
    assert (this->recup_rarete () == rarete);
    cout<<" ..... OK \n";

    cout<<"Experience donnee par le monstre : "<<experience_donnee;
    assert (this->recup_experience_donnee() == experience_donnee);
    cout<<" ..... OK \n";

    cout<<"Vie : "<<vie;
    assert (this->recup_vie () == vie);
    cout<<" ..... OK \n";

    cout<<"Force : "<<force;
    assert (this->recup_force () == force);
    cout<<" ..... OK \n";

    cout<<"Endurance : "<<endurance;
    assert (this->recup_endurance () == endurance);
    cout<<" ..... OK \n";

    cout<<"Vitesse : "<<vitesse;
    assert (this->recup_vitesse () == vitesse);
    cout<<" ..... OK \n";

    cout<<"Point d'action : "<<point_action;
    assert (this->recup_point_action() == point_action);
    cout<<" ..... OK \n \n";

    cout<<"Test de modification des champs : \n \n";

    this->modif_nom ("zizi");
    cout<<"Modification du nom : "<<nom;
    assert(nom == "zizi");
    cout<<" ..... OK \n";

    f_vie = vie;
    this->modif_vie (-10);
    cout<<"Modification de la vie : "<<vie;
    assert(vie == f_vie + -10);
    cout<<" ..... OK \n";

    f_force = force;
    this->modif_force (5);
    cout<<"Modification de la force : "<<force;
    assert(force == f_force + 5);
    cout<<" ..... OK \n";

    f_endurance = endurance;
    this->modif_endurance (-2);
    cout<<"Modification de l'endurance : "<<endurance;
    assert(endurance == f_endurance + -2);
    cout<<" ..... OK \n";

    f_vitesse = vitesse;
    this->modif_vitesse (15);
    cout<<"Modification de la vitesse : "<<vitesse;
    assert(vitesse == f_vitesse + 15);
    cout<<" ..... OK \n";

    f_point_action = point_action;
    this->modif_point_action(1);
    cout<<"Modification des points d'action : "<<point_action;
    assert(point_action == f_point_action + 1);
    cout<<" ..... OK \n";
}

void Monstre::auto_attaque(Creature* p_cible, string* p_nom_competence)
{
    int f_degats = 0;
    int f_degats_comparaison = 0;
    int f_buffer = -1;

    for(unsigned int i=0; i < nb_competence; i++)
    {
        if (est_selectionnable(tab_competence[i]))
        {
            f_degats_comparaison = tab_competence[i]->degats(this, p_cible);
            if(f_degats_comparaison > f_degats)
            {
                f_degats = f_degats_comparaison;
                f_buffer = i;
            }
        }
    }

    if (f_buffer >= 0)
    {
        point_action -= tab_competence[f_buffer]->recup_cout_point_action();
        mana -= tab_competence[f_buffer]->recup_cout_mana();
        p_cible->modif_vie(p_cible->recup_vie()-f_degats);
        *p_nom_competence = tab_competence[f_buffer]->recup_nom();
    }
    else
    {
        *p_nom_competence = "";
    }
}

bool Monstre::est_selectionnable(Competence * p_competence)
{
    return  ( p_competence->recup_cout_mana() <= mana && p_competence->recup_cout_point_action() <= point_action );
}
